package com.globalwave.common.entity;

import java.util.ArrayList;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.globalwave.common.Convertor;

public class VirtualEditForm {	
    private View view ;
    private List<Field> fields ;

	public View getView() {
		return view;
	}

	public void setView(View view) {
		this.view = view;
	}

    public List<Field> getFields() {
		return fields;
	}
	public void setFields(List<Field> fields) {
		this.fields = fields;
	}

	public void addFields(List<Object> fields) {
		this.fields = new ArrayList<Field>(fields.size());
		
		for (Object object:fields) {
			this.fields.add((Field)object);
		}
	}

    public String asXML() {
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement("module") ;
        
        try {
            root.add(Convertor.object2Xml(this.getView(), "view")) ;
            root.add(Convertor.list2Xml(this.getFields(), "fields")) ;

        } catch (Exception e) {
            root.addElement("message").addText("Conver grid to xml error!" + e.toString()) ;
        }
        
        return root.asXML() ;
    }
}
